/*
 * DayNamesHeader.java
 *
 * Created on Oct 19, 2011, 8:07:52 AM
 */
package carassius.GUI.Calendar;

import carassius.BLL.GregorianCalendarWithEvents;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.GregorianCalendar;
import java.util.ResourceBundle;

/**
 *
 * @author siebz0r
 */
public class DayNamesHeaderPanel
		extends javax.swing.JPanel
		implements PropertyChangeListener
{
	//<editor-fold defaultstate="collapsed" desc="Fields">
	private GregorianCalendarWithEvents _calendar;
	//</editor-fold>

	//<editor-fold defaultstate="collapsed" desc="Constructors">
	public DayNamesHeaderPanel()
	{
		this(new GregorianCalendarWithEvents());
	}

	public DayNamesHeaderPanel(int firstDay)
	{
		this(new GregorianCalendarWithEvents());
		_calendar.setFirstDayOfWeek(firstDay);
	}

	public DayNamesHeaderPanel(GregorianCalendarWithEvents cal)
	{
		_calendar = cal;
		initComponents();
		setLabels();
		_calendar.addPropertyChangeListener("firstDayOfWeek", this);
	}
	//</editor-fold>

	//<editor-fold defaultstate="collapsed" desc="Private methods">
	private void setLabels()
	{
		ResourceBundle bundle = ResourceBundle.getBundle("carassius.GUI.Calendar.resources.day");
		GregorianCalendar cal = (GregorianCalendar) _calendar.clone();
		cal.set(GregorianCalendar.DAY_OF_WEEK, _calendar.getFirstDayOfWeek());

		String day = Integer.toString(cal.get(GregorianCalendar.DAY_OF_WEEK));
		StringBuilder sb = new StringBuilder(day);
		sb.append("s");
		uxDayLabel1.setText(bundle.getString(sb.toString()));
		uxDayLabel1.setToolTipText(bundle.getString(day));
		cal.roll(GregorianCalendar.DAY_OF_WEEK, true);
		sb.setLength(0);

		day = Integer.toString(cal.get(GregorianCalendar.DAY_OF_WEEK));
		sb.append(day);
		sb.append("s");
		uxDayLabel2.setText(bundle.getString(sb.toString()));
		uxDayLabel2.setToolTipText(bundle.getString(day));
		cal.roll(GregorianCalendar.DAY_OF_WEEK, true);
		sb.setLength(0);

		day = Integer.toString(cal.get(GregorianCalendar.DAY_OF_WEEK));
		sb.append(day);
		sb.append("s");
		uxDayLabel3.setText(bundle.getString(sb.toString()));
		uxDayLabel3.setToolTipText(bundle.getString(day));
		cal.roll(GregorianCalendar.DAY_OF_WEEK, true);
		sb.setLength(0);

		day = Integer.toString(cal.get(GregorianCalendar.DAY_OF_WEEK));
		sb.append(day);
		sb.append("s");
		uxDayLabel4.setText(bundle.getString(sb.toString()));
		uxDayLabel4.setToolTipText(bundle.getString(day));
		cal.roll(GregorianCalendar.DAY_OF_WEEK, true);
		sb.setLength(0);

		day = Integer.toString(cal.get(GregorianCalendar.DAY_OF_WEEK));
		sb.append(day);
		sb.append("s");
		uxDayLabel5.setText(bundle.getString(sb.toString()));
		uxDayLabel5.setToolTipText(bundle.getString(day));
		cal.roll(GregorianCalendar.DAY_OF_WEEK, true);
		sb.setLength(0);

		day = Integer.toString(cal.get(GregorianCalendar.DAY_OF_WEEK));
		sb.append(day);
		sb.append("s");
		uxDayLabel6.setText(bundle.getString(sb.toString()));
		uxDayLabel6.setToolTipText(bundle.getString(day));
		cal.roll(GregorianCalendar.DAY_OF_WEEK, true);
		sb.setLength(0);

		day = Integer.toString(cal.get(GregorianCalendar.DAY_OF_WEEK));
		sb.append(day);
		sb.append("s");
		uxDayLabel7.setText(bundle.getString(sb.toString()));
		uxDayLabel7.setToolTipText(bundle.getString(day));
	}
	//</editor-fold>

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        uxDayLabel1 = new javax.swing.JLabel();
        uxDayLabel2 = new javax.swing.JLabel();
        uxDayLabel3 = new javax.swing.JLabel();
        uxDayLabel4 = new javax.swing.JLabel();
        uxDayLabel5 = new javax.swing.JLabel();
        uxDayLabel6 = new javax.swing.JLabel();
        uxDayLabel7 = new javax.swing.JLabel();

        setMaximumSize(new java.awt.Dimension(189, 20));
        setMinimumSize(new java.awt.Dimension(189, 20));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(189, 20));
        setLayout(new java.awt.GridLayout(1, 0));

        uxDayLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(carassius.CarassiusApp.class).getContext().getResourceMap(DayNamesHeaderPanel.class);
        uxDayLabel1.setText(resourceMap.getString("uxDayLabel1.text")); // NOI18N
        uxDayLabel1.setName("uxDayLabel1"); // NOI18N
        add(uxDayLabel1);

        uxDayLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        uxDayLabel2.setText(resourceMap.getString("uxDayLabel2.text")); // NOI18N
        uxDayLabel2.setName("uxDayLabel2"); // NOI18N
        add(uxDayLabel2);

        uxDayLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        uxDayLabel3.setText(resourceMap.getString("uxDayLabel3.text")); // NOI18N
        uxDayLabel3.setName("uxDayLabel3"); // NOI18N
        add(uxDayLabel3);

        uxDayLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        uxDayLabel4.setText(resourceMap.getString("uxDayLabel4.text")); // NOI18N
        uxDayLabel4.setName("uxDayLabel4"); // NOI18N
        add(uxDayLabel4);

        uxDayLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        uxDayLabel5.setText(resourceMap.getString("uxDayLabel5.text")); // NOI18N
        uxDayLabel5.setName("uxDayLabel5"); // NOI18N
        add(uxDayLabel5);

        uxDayLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        uxDayLabel6.setText(resourceMap.getString("uxDayLabel6.text")); // NOI18N
        uxDayLabel6.setName("uxDayLabel6"); // NOI18N
        add(uxDayLabel6);

        uxDayLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        uxDayLabel7.setText(resourceMap.getString("uxDayLabel7.text")); // NOI18N
        uxDayLabel7.setName("uxDayLabel7"); // NOI18N
        add(uxDayLabel7);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel uxDayLabel1;
    private javax.swing.JLabel uxDayLabel2;
    private javax.swing.JLabel uxDayLabel3;
    private javax.swing.JLabel uxDayLabel4;
    private javax.swing.JLabel uxDayLabel5;
    private javax.swing.JLabel uxDayLabel6;
    private javax.swing.JLabel uxDayLabel7;
    // End of variables declaration//GEN-END:variables

	@Override
	public void propertyChange(PropertyChangeEvent evt)
	{
		if ("firstDayOfWeek".equals(evt.getPropertyName()))
		{
			setLabels();
		}
	}
}
